﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LotteryAdmin.AdminService;
namespace LotteryAdmin
{
    public partial class AdminChangePwd : ChildWindow
    {
        LotteryAdminClient srv;
        public AdminChangePwd()
        {
            InitializeComponent();
            srv = WcfProxy.GetProxy;
            srv.ChangeAdminPwdCompleted += new EventHandler<ChangeAdminPwdCompletedEventArgs>(srv_ChangeAdminPwdCompleted);
        }

        void srv_ChangeAdminPwdCompleted(object sender, ChangeAdminPwdCompletedEventArgs e)
        {
            loadingProgress.IsBusy = false;
            if (e.Result)
            {
                this.DialogResult = true;
            }
            else
            {
                MessageBox.Show("网络错误或者服务器繁忙不可连接!");
            }
        }
        public void ShowWindow(string userid)
        {
            this.tb_UserId.Text = userid;
            base.Show();
        }
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (!Validate.ValidateInputModify(pb_oldPwd.Password) ||
                App.Session["UserPwd"].ToString() != pb_oldPwd.Password)
            {
                MessageBox.Show("当前密码错误!");
                return;
            }
            if (!Validate.ValidateInputModify(pb_oldPwd.Password))
            {
                MessageBox.Show("新密码输入不合法!只能接受数字、字母、下划线!");
                return;
            }
            srv.ChangeAdminPwdAsync(tb_UserId.Text, pb_newPwd.Password);
            loadingProgress.IsBusy = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

